<template>
  <div class="full-screen-wrapper" @click="handleFullscreen">
      <i :class="['icon', !isFullscreen ? 'vue-dsn-icon-fullscreen' : 'vue-dsn-icon-tuichuquanping']" />
  </div>
</template>
<script>
import screenfull from 'screenfull'
export default {
  name: 'FullScreen',
  data () {
    return {
      isFullscreen: false
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    handleFullscreen () {
      if (screenfull.enabled) {
        this.$message({
          message: '不支持全屏',
          type: 'warning'
        })
        return false
      }
      screenfull.toggle()
    },
    change () {
      this.isFullscreen = screenfull.isFullscreen
    },
    init () {
      if (!screenfull.enabled) {
        screenfull.on('change', this.change)
      }
    },
    destroy () {
      if (!screenfull.enabled) {
        screenfull.off('change', this.change)
      }
    }
  },
  beforeDestroy () {
    this.destroy()
  }
}
</script>
<style lang="scss" scoped>
.full-screen-wrapper {
  // float: left;
  position: fixed;
  left: 10;
  top: 0;
  // background: #fff;
  z-index: 10009;
  width: 22px;
  height: 22px;
  line-height: 22px;
  margin-top: 5px;
  color: #fff;
  cursor: pointer;
  .icon {
    font-size: 24px;
  }
  &:hover {
    color: #409eff;
  }
}
</style>
